package luceneqe.modelsIR.clauses;

import java.util.ArrayList;
import java.util.List;

import org.apache.lucene.analysis.Analyzer;

import luceneqe.analysis.WordPreprocessor;


public class Clause {
	
	List<String> termList;
	List<Double> weights;
	
	public Clause() {
		this.termList = new ArrayList<String>();
		this.weights = new ArrayList<Double>();
	}
	
	public Clause(String terms){
		this.termList = new ArrayList<String>();
		this.weights = new ArrayList<Double>();
		String[] c = terms.split(" ");
		for(int i=0;i<c.length;i++){
			if(c[i].contains("^")) {
				String[] unit = c[i].split("\\^");
				//termList.add(WordPreprocessor.getEnglishStem(unit[0]));
				termList.add(unit[0]);
				this.weights.add(Double.parseDouble(unit[1]));
			}
			else {
				//this.termList.add(WordPreprocessor.getEnglishStem(c[i]));
				this.termList.add(c[i]);
				this.weights.add(1.0);
			}
		}
	}
	
//	public void addTerm(String t) {
//		this.termList.add(WordPreprocessor.getEnglishStem(t));
//		this.termList.add(t);
//		this.weights.add(1.0);
//	}
//	
//	public void addTerm(String t, double d) {
//		this.termList.add(WordPreprocessor.getEnglishStem(t));
//		this.termList.add(t);
//		this.weights.add(d);
//	}
	
	public int length(){
		return this.termList.size();
	}
	
	public String getTerm(int i) {
		return this.termList.get(i);
	}
	
	public float getWeigth(String t) {
		return new Float(this.weights.get(this.termList.indexOf(t))).floatValue();
	}
	
	public String toString() {
		return this.termList.toString();
	}
	
	public String getTermForIDF() {
		return this.termList.get(0);
	}
	
	public Double getBoost(int i) {
		return this.weights.get(i);
	}

}
